home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Online / arws / webserver.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-01-29  |  2.0 KB  |  73 lines

  1. /*
  2.    ARexx Web Server
  3.    Version 1.1 
  4. */
  5.  
  6. if ~show('L','rexxsupport.library') then addlib('rexxsupport.library',0,-30,0)
  7.  
  8. path="amitcp:www"   /* No trailing "/"!! */
  9. pull a
  10. file=subword(a,2,1)
  11. if right(file,1)="/" then file=file"index.html"
  12. if index(upper(file),".CGI")~=0 then signal cgi
  13. if exists(path||file)=0 then bad=1
  14. if index(file,"//")~=0 then signal error
  15. if index(file,":")~=0 then signal error
  16. ext=upper(substr(file,lastpos(".",file),length(ext)))
  17. mime="text/html"
  18. if ext="HTML"|ext="HTM"|ext="HML" then mime="text/html"
  19. if ext="DOC"|ext="TXT" then mime="text/plain"
  20. if ext="GUIDE" then mime="text/aguide"
  21. if ext="GIF" then mime="image/gif"
  22. if ext="JPG"|ext = 'JPEG' then mime="image/jpeg"
  23. if ext="WAV"|ext="AU"|ext="8SVX" then mime="audio/*"
  24. if ext="LHA"|ext="LZH"|ext="LZX" then mime="application/octet-stream"
  25. say "HTTP/1.0 200 OK"
  26. say "Server: RexxWebServer/1.0"
  27. say "Date: "||date()||" "||time()
  28. say "Accept-ranges: bytes"
  29. say "Content-length: "||subword(statef(path||file),2,1)
  30. say "Content-type: "||mime
  31. if bad=1 then signal bad
  32. say ""
  33. call open(1,path||file,'r')
  34. do until eof(1)=1
  35. a=readln(1)
  36. if index(a,"<! CGI=")~=0 then call cgi_html
  37. say a
  38. end
  39. exit
  40.  
  41. cgi:
  42. cgi=substr(file,lastpos("/",file)+1)
  43. cgi=translate(cgi," ","?")
  44. if exists(path||"/cgi-bin/"||subword(cgi,1,1))=0 then signal bad
  45. say "HTTP/1.0 200 OK"
  46. say "Server: RexxWebServer/1.0"
  47. say "Date: "||date()||" "||time()
  48. say ""
  49. address command "rx "||path||"/cgi-bin/"||cgi
  50. exit
  51.  
  52. cgi_html:
  53. parse var a null'<! CGI="'rexx'">'stuff
  54. say null
  55. address command "rx "||path||"/cgi-bin/"||rexx
  56. say stuff
  57. a=""
  58. return
  59.  
  60. bad:
  61. say "HTTP/1.0 404 Not Found"
  62. say "Content-Type: text/html"
  63. say ""
  64. say "<HTML><STRONG><H1>ERROR</H1></STRONG><H4><P><P>ARexxWebServer error 404:<BR> Page does not exist<BR>FILENAME: "||file||"</HTML>"
  65. exit
  66.  
  67. error:
  68. say "HTTP/1.0 400 Forbidden"
  69. say "Content-Type: text/html"
  70. say ""
  71. say "<STRONG><H1>ERROR</H1></STRONG><H4><P><P>ARexxWebServer error 400:<BR> You may not place : or double //'s in a URL<BR>FILENAME: "||file||"</HTML>"
  72. exit
  73.